package com.hsogoo.stalker.agent;

import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.util.TraceClassVisitor;

import java.io.InputStream;
import java.io.PrintWriter;

/**
 * 此类可以打印出类的字节码
 * @Author huangsaigang
 * Created @2020-03-04.
 */
public class AsmClassPrinter {

    //定义需要打印的类
    private static Class clazz = TestClass.class;

    public static void main(String[] args) throws Exception {
        String path = "/" + clazz.getName().replaceAll("[.]", "/") + ".class";
        InputStream inputStream = AsmClassPrinter.class.getResourceAsStream(path);
        ClassReader reader = new ClassReader(inputStream);
        reader.accept(new TraceClassVisitor(new PrintWriter(System.out)), ClassReader.SKIP_FRAMES);
    }

}
